<?php
namespace app\tactics\admin;

use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use app\admin\model\Area as AreaModel;
use think\Db;
/**
 *
 */
class Tags extends Admin
{
		/**
        * 地区列表
        * @author 陈梦晨 <2391157750@qq.com>
        * @return mixed
        */
       //标签管理
	public function index(){
		return ZBuilder::make('table')->setPageTitle('标签管理')->fetch();
	}

    /**
    * 日志详情
    * @param null $id 日志id
    * @author 蔡伟明 <314013107@qq.com>
    */
    public function edit($id = null)
    {
		if ($id === null) return $this->error('缺少参数');
		$info = AreaModel::find(['id' => $id]);


		$list_province = db("admin_area")->where("parentid=0")->column("id,name");
		// 使用ZBuilder快速创建表单
		return ZBuilder::make('form')
			->setPageTitle('编辑') // 设置页面标题
			->addFormItems([ // 批量添加表单项
				['hidden', 'id'],
                   ['text', 'name', '地区名称'],
				])
			->addLinkage('province', '选择省份', '', $list_province, '', url('get_city'), 'city,area')
			->addLinkage('city', '选择城市', '', '', '', url('get_area'), 'area')
			->addSelect('area', '选择地区')
			->addRadio('status', '状态', '', ['0' => '禁用', '1' => '启用'])
			->setFormData($info) // 设置表单数据
			->layout(['province' => 3, 'city' => 3, 'area' => 3, 'status' => 3])
			->fetch();
    }
       public function add(){
           return $this->fetch();
       }

       public function get_city($province = '') {
           $result = db("admin_area")->where("parentid=" . $province)->column("id,name");

           $arr['code'] = '1'; //判断状态
           $arr['msg'] = '请求成功'; //回传信息
           $arr['list'] = $result; //数据
           return json($arr);
       }

       public function get_area($city = '') {
           $result = db("admin_area")->where("parentid=" . $city)->column("id,name");

           $arr['code'] = '1'; //判断状态
           $arr['msg'] = '请求成功'; //回传信息
           $arr['list'] = $result; //数据
           return json($arr);
       }
}
